package cn.timeapi.Applet.Mall.CatSquare.controller.portal;

import cn.timeapi.Applet.Mall.CatSquare.common.ServerResponse;
import cn.timeapi.Applet.Mall.CatSquare.dao.ProductMapper;
import cn.timeapi.Applet.Mall.CatSquare.entity.Product;
import cn.timeapi.Applet.Mall.CatSquare.service.IProductService;
import cn.timeapi.Applet.Mall.CatSquare.vo.ProductDetailVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 描述:前台商品管理
 * @author Vincent Vic
 * create 2020-02-19 14:34
 */
@Api("product")
@RestController
@RequestMapping("/product/")   //请求地址设置
public class ProductController {

    @Autowired
    private IProductService iProductService;

    @Autowired
    private ProductMapper productMapper;

    //获取产品详情
    @ApiOperation("获取产品详情")
    @GetMapping("get_detail")
    @ResponseBody   //自动序列化Json
    public ServerResponse<ProductDetailVo> getDetail(Integer productId){
        return iProductService.manageProductDetail(productId);
    }

    //获取产品列表
    @ApiOperation("获取产品列表")
    @GetMapping("list")
    @ResponseBody   //自动序列化Json
    public ServerResponse<PageInfo> list(@ApiParam("搜索关键字") @RequestParam(value = "keyword",required = false)String keyword,
                                         @ApiParam("分类id") @RequestParam(value = "categotyId",required = false)Integer categotyId,
                                         @ApiParam("分页起始 默认：1") @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                         @ApiParam("分页大小 默认：10") @RequestParam(value = "pageSize",defaultValue = "10") int pageSize,
                                         @ApiParam("排序规则 例如price_desc，price_asc") @RequestParam(value = "orderBy",defaultValue = "") String orderBy){
      //  return iProductService.manageProductDetail(0);
        System.out.println(keyword+","+categotyId);
        return iProductService.getProductByKeywordCategory(keyword,categotyId,pageNum,pageSize,orderBy);
    }

    //获取产品列表
    @ApiOperation("微信登入")
    @GetMapping("listAll")
    @ResponseBody   //自动序列化Json
    public ServerResponse<List<Product>> listAll(){
        System.out.println("1111");
        //  return iProductService.manageProductDetail(0);
        return ServerResponse.success(productMapper.selectByNameAndCategoryIds("%手机%", null));
    }
}